﻿using System;
using System.Xml;
using Notoric.Model.Internal;
using Notoric.Model.Packaging;
using Notoric.Model.Validation;

namespace Notoric.Model.Elements
{
    /// <summary>
    /// Represents a tie.
    /// </summary>
    /// <remarks>
    /// The <see cref="TieElement"/> is a horizontal <see cref="ConnectorElement"/>.
    /// It connects symbols from different beats and indicates that they should be played
    /// as one long symbol with a duration equal to the sum of the connected symbols.
    /// </remarks>
    public class TieElement : ConnectorElement
    {
        #region Constructors

        /// <summary>
        /// Creates a new <see cref="TieElement"/> instance.
        /// </summary>
        /// <param name="packagePart">
        /// <para>
        /// Type: <see cref="CompositionPart"/>
        /// </para>
        /// <para>
        /// The package part that owns this element.
        /// </para>
        /// </param>
        /// <param name="owner">
        /// <para>
        /// Type: <see cref="CompositionElement"/>
        /// </para>
        /// <para>
        /// The model element that directly owns this element.
        /// </para>
        /// </param>
        /// <param name="start">
        /// <para>
        /// Type: <see cref="DurationalSymbolElement"/>
        /// </para>
        /// <para>
        /// The durational symbol at which the tie starts.
        /// </para>
        /// </param>
        /// <param name="end">
        /// <para>
        /// Type: <see cref="DurationalSymbolElement"/>
        /// </para>
        /// <para>
        /// The durational symbol at which the tie ends.
        /// </para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="packagePart"/> or <paramref name="owner"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ValidationException">
        /// The <paramref name="start"/> or <paramref name="end"/> is not valid.
        /// </exception>
        public TieElement(CompositionPart packagePart, CompositionElement owner, DurationalSymbolElement start, DurationalSymbolElement end)
            : base(packagePart, owner, start, end)
        {
            
        }

        /// <summary>
        /// Creates a new <see cref="TieElement"/> instance.
        /// </summary>
        /// <param name="packagePart">
        /// <para>
        /// Type: <see cref="CompositionPart"/>
        /// </para>
        /// <para>
        /// The package part that owns this element.
        /// </para>
        /// </param>
        /// <param name="owner">
        /// <para>
        /// Type: <see cref="CompositionElement"/>
        /// </para>
        /// <para>
        /// The model element that directly owns this element.
        /// </para>
        /// </param>
        /// <param name="element">
        /// <para>
        /// Type: <see cref="XmlElement"/>
        /// </para>
        /// <para>
        /// The XML element that holds the data of this object.
        /// </para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Any of the arguments is <see langword="null"/>.
        /// </exception>
        internal TieElement(CompositionPart packagePart, CompositionElement owner, XmlElement element)
            : base(packagePart, owner, element)
        {
            
        }

        #endregion

        #region ModelElement Members

        /// <inheritdoc/>
        protected override XmlElement CreateSymbolElement(XmlDocument document)
        {
            return document.CreateElement(
                PackageVocabulary.PackageNamespacePrefix,
                PackageVocabulary.TieElementName,
                PackageVocabulary.PackageNamespaceUri
                );
        }

        #endregion
    }
}
